<?php include ROOT_PATH."/lib/common/calendar.php"; ?>
<?php $leaveTypes = $records['leaveType']?>
<?php $employees = $records['employees']?>
<?php $selectedId = $records['selectedId']?>
<?php $fromDate = isset($records['fromDate']) ? LocaleUtil::getInstance()->formatDate($records['fromDate']) : null;?>
<?php $toDate = isset($records['toDate']) ? LocaleUtil::getInstance()->formatDate($records['toDate']) : null;?>
<?php $records = $records['leaves']?>
<?php $exportURL = "./CentralController.php?leavecode=Leave&action=Leave_FetchLeaveTaken&export=1";?>
<script language="javascript">   
    function exportData(){
       var action =  '<?php echo $exportURL; ?>';
       var fromDate = document.frmFilterLeave.txtFromDate.value;
       if(fromDate){
           action = action + "&txtFromDate=" + fromDate;
       }
       var toDate = document.frmFilterLeave.txtToDate.value;
       if(toDate){
           action = action + "&txtToDate=" + toDate;
       }
       var empId = document.frmFilterLeave.empId.value;
       if(empId){
           action = action +  "&empId=" + empId;
       }       
       location.href = action;
    }
</script>
<h2>Taken Leaves</h2><hr/>
<div id="filterLeavePane">   
<form id="frmFilterLeave" name="frmFilterLeave" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="hidden" name="leavecode" value="Leave"/>
    <input type="hidden" name="action" value="Leave_FetchLeaveTaken"/>
  <table border="0" cellpadding="0" cellspacing="0">
    <thead>
      <tr>
        <th class="tableTopLeft"></th>
        <th class="tableTopMiddle"></th>
        <th class="tableTopMiddle"></th>
        <th class="tableTopMiddle"></th>
        <th class="tableTopRight"></th>
      </tr>
    </thead>
  <tbody>
  <tr>
  <td class="tableMiddleLeft"></td> 
  <td>
      &nbsp;&nbsp;
      From
      <span>
          <input name="txtFromDate" type="text" id="txtFromDate"  size="11" value="<?php echo $fromDate;?>"/>&nbsp;
          <input type="button" name="Submit" value="  " class="calendarBtn" />
      </span>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      
  </td>
  <td>
      To
     <span>
         <input name="txtToDate" type="text" id="txtToDate" size="11" value="<?php echo $toDate;?>" />&nbsp;
         <input type="button" name="Submit" value="  " class="calendarBtn" />
     </span>
  </td>
  <td>
      <input type='image' class='button1' title="Search" name="Search"
		src="../../themes/beyondT/pictures/btn_search.gif"
		onMouseOut="this.src='../../themes/beyondT/pictures/btn_search.gif';;"
		onMouseOver="this.src='../../themes/beyondT/pictures/btn_search_02.gif';"/>
  </td>
  
  <td class="tableMiddleRight"></td>
  </tr>

  <tr>
  <td class="tableMiddleLeft"></td>
  <td colspan="2">
      <table>
          <tr>
               <td>
                    Employee:
                </td>
                <td>
                    <select name="empId" id="empId">
                        <option value="">Select employee</option>
                        <?php foreach ($employees as $emp):?>
                        <option value="<?php echo $emp[0]?>" <?php echo $selectedId ==$emp[0]?"selected":"";?>  ><?php echo $emp[1]?></option>
                        <?php endforeach;?>
                    </select>
                </td>  
          </tr>
      </table>
  </td>
  <td>&nbsp;&nbsp;&nbsp;<input type="button" value="Export" onclick="javascript:exportData()" /></td>
 
<td class="tableMiddleRight"></td>
</tr>
	</tbody>
    <tfoot>
      <tr>
        <td class="tableBottomLeft"></td>
        <td class="tableBottomMiddle"></td>
        <td class="tableBottomMiddle"></td>
        <td class="tableBottomMiddle"></td>
        <td class="tableBottomRight"></td>
      </tr>
    </tfoot>
	</table>
</form>
</div>
<?php if (count($records) == 0) {?>
<h5>No records found!</h5>
<?php } else {?>
<?php
if (isset($_GET['message']) && $_GET['message'] == "Success") {
?>
<font color="#009933" size="-1" face="Verdana, Arial, Helvetica, sans-serif">
<?php
	echo $lang_Leave_CANCEL_SUCCESS;
} else if (isset($_GET['message']) && $_GET['message'] == "Failiure") {
?>
<font color="#ff0000" size="-1" face="Verdana, Arial, Helvetica, sans-serif">
<?php
	echo $lang_Leave_CANCEL_FAILURE;
}
?>
</font>

<form id="frmCancelTakenLeave" name="frmCancelTakenLeave" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?leavecode=Leave&action=Leave_CancelTakenLeaves">

<table border="0" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="tableTopLeft"></th>
<th class="tableTopMiddle"></th>
<th class="tableTopMiddle"></th>
<th class="tableTopMiddle"></th>
<th class="tableTopMiddle"></th>
<th class="tableTopMiddle"></th>
<th class="tableTopMiddle"></th>
<th class="tableTopRight"></th>
</tr>

<tr>
<th class="tableMiddleLeft"></th>
<th width="100px" class="tableMiddleMiddle"><?php echo $lang_Leave_Common_Date; ?></th>
<th width="200px" class="tableMiddleMiddle"><?php echo $lang_Leave_Common_EmployeeName; ?></th>
<th width="50px" class="tableMiddleMiddle"><?php echo $lang_Leave_NoOfHours; ?></th>
<th width="90px" class="tableMiddleMiddle"><?php echo $lang_Leave_Common_LeaveType; ?></th>
<th width="100px" class="tableMiddleMiddle"><?php echo $lang_Leave_Common_Status; ?></th>
<th width="150px" class="tableMiddleMiddle"><?php echo $lang_Leave_Common_Comments; ?></th>
<th class="tableMiddleRight"></th>
</tr>
</thead>
<tbody>

<?php

$j = 0;
if (is_array($records)) {
	foreach ($records as $record) {
		if(!($j%2)) {
			$cssClass = 'odd';
		} else {
			$cssClass = 'even';
		}
	$j++;

?>

<input type="hidden" name="leaveId[]" value="<?php echo $record->getLeaveId(); ?>" />
<input type="hidden" name="leaveTypeId[]" value="<?php echo $record->getLeaveTypeId(); ?>" />
<input type="hidden" name="employeeId[]" value="<?php echo $record->getEmployeeId(); ?>" />
<input type="hidden" name="leaveYear[]" value="<?php echo substr($record->getLeaveDate(), 0, 4); ?>" />
<input type="hidden" name="noHours[]" value="<?php echo $record->getNoHours(); ?>" />
<tr>
<td class="tableMiddleLeft"></td>
<td class="<?php echo $cssClass; ?>"><?php echo $record->getLeaveDate(); ?></td>
<td class="<?php echo $cssClass; ?>"><?php echo $record->getEmployeeName(); ?></td>
<td class="<?php echo $cssClass; ?>"><?php echo $record->getNoHours(); ?></td>
<td class="<?php echo $cssClass; ?>">
<select name="leaveTypeId<?php echo $record->getLeaveId()?>">
<?php foreach ($leaveTypes as $type):?>    
    <option value = "<?php echo $type->getLeaveTypeID()?>" <?php echo $type->getLeaveTypeID()== $record->getLeaveTypeID()?'selected':''?>><?php echo $type->getLeaveTypeName()?></option>    
<?php endforeach;?>
</select>
</td>

<td class="<?php echo $cssClass; ?>">
<select name="leaveStatus[]">
<option value="3" selected="selected" ><?php echo $lang_Leave_Common_Taken; ?></option>
<option value="0"><?php echo $lang_Leave_Common_Cancel; ?></option>
</select>
</td>
<td class="<?php echo $cssClass; ?>">
<input type="text"  name="leaveComments[]" value="<?php echo $record->getLeaveComments(); ?>" />
</td>
<td class="tableMiddleRight"></td>
</tr>

<?php } } ?>

</tbody>
<tfoot>
<tr>
<td class="tableBottomLeft"></td>
<td class="tableBottomMiddle"></td>
<td class="tableBottomMiddle"></td>
<td class="tableBottomMiddle"></td>
<td class="tableBottomMiddle"></td>
<td class="tableBottomMiddle"></td>
<td class="tableBottomMiddle"></td>
<td class="tableBottomRight"></td>
</tr>
</tfoot>

</table>
<p id="controls">
<input type="image" name="Save" class="save" src="../../themes/beyondT/pictures/btn_save.gif"/>
</p>
<?php } ?>
</form>
<div id="cal1Container" style="position:absolute;" ></div>

